package com.bulldog.spider.console;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.bulldog.spider.DepartRepo;
import lombok.extern.java.Log;
import org.apache.commons.lang3.StringUtils;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.Iterator;
import java.util.ListIterator;
import java.util.Map;

@Log
public class GroupConsolePipeLine implements Pipeline {

    @Override
    public void process(ResultItems resultItems, Task task) {
        log.info("捕获页面");
        log.info(resultItems.getRequest().getUrl());
        Iterator iterator = resultItems.getAll().entrySet().iterator();

        while(iterator.hasNext()) {
            Map.Entry<String, Object> entry = (Map.Entry)iterator.next();
            Object object = entry.getValue();
            // 姓名
            System.out.println(((DepartRepo)object).name.toString().replaceAll(" /", ""));
            // 简介
            ListIterator<String> listIntroduction = ((DepartRepo)object).introduction.listIterator();
            while (listIntroduction.hasNext()) {
                System.out.println(listIntroduction.next().toString());
                break;
            }
            // 履历
            ListIterator<String> listResume = ((DepartRepo)object).resume.listIterator();
            while (listResume.hasNext()) {
                System.out.println(listResume.next().toString().replaceFirst("\n",""));
            }
        }

    }
}